package cn.xd.security.service;

import cn.xd.base.application.service.query.GlobalAppUserQueryAppService;
import cn.xd.base.domain.entity.GlobalAppUser;
import cn.xd.security.userDetail.CustomerUserDetails;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsPasswordService;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service("CustomerUserDetailServiceImpl")
@RequiredArgsConstructor
public class CustomerUserDetailServiceImpl implements UserDetailsService, UserDetailsPasswordService {
    private final GlobalAppUserQueryAppService globalAppUserQueryAppService;

    @Override
    public UserDetails updatePassword(UserDetails user, String newPassword) {
        return null;
    }

    @Override
    public UserDetails loadUserByUsername(String phone) throws UsernameNotFoundException {
        GlobalAppUser globalAppUser = globalAppUserQueryAppService.getGeneralUserByPhone(phone).isEmptyThrow("未找到用户");
        return CustomerUserDetails.newCustomerUserDetails(globalAppUser);
    }
}
